package com.example.ivideo_2211a.widget

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import com.example.ivideo_2211a.R

class GoldCoinRewardDialog(
    context: Context,
    private val amount: Int,
    private val onCollect: (() -> Unit)? = null
) : Dialog(context, R.style.GoldCoinDialog) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val view = LayoutInflater.from(context).inflate(R.layout.dialog_gold_coin_reward, null)
        setContentView(view)
        setCancelable(false)
        setCanceledOnTouchOutside(false)

        // 设置弹窗宽度为屏幕宽度的80%
        window?.setLayout((context.resources.displayMetrics.widthPixels * 0.8).toInt(),
            android.view.WindowManager.LayoutParams.WRAP_CONTENT)
        window?.setBackgroundDrawableResource(android.R.color.transparent)

        view.findViewById<TextView>(R.id.tv_reward_amount).text = "+$amount 金币"
        view.findViewById<Button>(R.id.btn_collect).setOnClickListener {
            onCollect?.invoke()
            dismiss()
        }
        view.findViewById<ImageView>(R.id.iv_close).setOnClickListener {
            onCollect?.invoke()
            dismiss()
        }
    }
}
